from django.http import HttpResponse
import random

dynamite_remaining = 0
draw_counter = 0

def mcgyver_bot(request):
    global dynamite_remaining
    chosen_play = random.choice(('rock', 'paper', 'scissors',))
    
    if draw_counter > 1 and dynamite_remaining > 0:
        chosen_play = "dynamite"
        dynamite_remaining -= 1
    return HttpResponse(chosen_play)

def mcgyver_bot_outcome(request):
    global draw_counter
    data = eval(request["data"])
    if data["contestant1"] == data["contestant2"]:
        draw_counter += 1
    else:
        draw_counter = 0
    return HttpResponse("ok")

def mcgyver_bot_introduction(request):
    data = eval(request["data"])
    global dynamite_remaining, draw_counter
    draw_counter = 0
    dynamite_remaining = int(float(data["round_count"]) * .05)
    return HttpResponse("{\"bot_name\":\"McGyver\", \"author\":\"Justin Bozonier\"}")